﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VehicleOOBWeb.Filters;
using VehicleOOBWeb.Models;

namespace VehicleOOBWeb.Controllers
{
    [InitializeSimpleMembership]
    [Authorize]
    
    public class ManufacturerController : Controller
    {
        //
        // GET: /Manufacturer/

        public ActionResult Index(int? page)
        {
            if (Request.HttpMethod != "GET")
            {
                if (!page.HasValue)
                {
                    page = 1;
                }
            }
            int pageNumber = (page ?? 1);
            return View(ManufacturerService.GetListManufacturersPagging(pageNumber));
        }

        //
        // GET: /Manufacturer/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Manufacturer/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Manufacturer/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                Manufacturer manufacturer = new Manufacturer();
                UpdateModel(manufacturer);
                ManufacturerService.AddManufacturer(manufacturer);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Manufacturer/Edit/5

        public ActionResult Edit(int id)
        {
            
            return View(ManufacturerService.GetManufacturerByCode(id));
        }

        //
        // POST: /Manufacturer/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        public ActionResult Delete(int id)
        {
            try
            {
                ManufacturerService.DeleteManufacturer(id);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
